package cn.itcast.mq.listener;


import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

@Configuration
public class SpringRabbitListener {

   /* @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String msg) {

        System.out.println("spring AMQP消费者接受到的消息： 【"+msg+"】");
    }
*/

    /**
     * 工作队列
     * @param message
     * @throws InterruptedException
     */
    @RabbitListener(queues = "simple.queue")
    public void listenWorkQueue1(String message)throws InterruptedException{


        System.out.println("工作消费者1接收到消息：【"+message+"】"+LocalDateTime.now());
        Thread.sleep(20);
    }
    /**
     * 工作队列2
     * @param message
     * @throws InterruptedException
     */
    @RabbitListener(queues = "simple.queue")
    public void listenWorkQueue2(String message)throws InterruptedException{


        System.err.println("工作消费者2接收到消息：【"+message+"】"+ LocalDateTime.now());
        Thread.sleep(200);
    }

    /**
     * 广播模式队列1
     * @param message
     */
    @RabbitListener(queues = "sysion1.queue1")
    public void listenFanoutQueue1(String message){
        System.out.println("广播消费者1接受到Fanout消息【"+message+"】：");
    }
    /**
     * 广播模式队列2
     * @param message
     */
    @RabbitListener(queues = "sysion2.queue2")
    public void listenFanoutQueue2(String message){
        System.out.println("广播消费者2接受到Fanout消息【"+message+"】：");
    }


}
